home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga CD-ROM Collection
/
Amiga CD-ROM Collection - Auge 4000 and Cactus and Demo Util.iso
/
auge4000
/
46
/
lib
/
extra
/
getfnl.c
next >
Wrap
C/C++ Source or Header
|
1990-06-20
|
2KB
|
97 lines
/*
* GETFNL.C
*
* (c)Copyright 1990, Matthew Dillon, All Rights Reserved
*/
#include <exec/types.h>
#include <libraries/dos.h>
#include <stdlib.h>
#include <errno.h>
typedef struct FileInfoBlock FIB;
extern void *_ParseWild();
int
getfnl(pat, buf, bufSize, attr)
const char *pat;
char *buf;
size_t bufSize;
int attr; /* 0 = files, 1 = files & dirs */
{
BPTR lock;
FIB *fib = malloc(sizeof(FIB));
int r = -1;
void *wildNode = NULL;
errno = 0;
_SetWildStack(2048);
--bufSize; /* final \0 at end */
if (fib) {
const char *ptr;
BPTR lock;
for (ptr = pat + strlen(pat); ptr >= pat; --ptr) {
if (*ptr == '/' || *ptr == ':')
break;
}
++ptr; /* points to just after the last / or :, */
/* or to the beginning if no / or : */
/*
* can't modify a const string !
*/
wildNode = _ParseWild(ptr, strlen(ptr));
{
short len = ptr - pat;
char *hdr = malloc(len + 1);
strncpy(hdr, pat, len);
hdr[len] = 0;
lock = Lock(hdr, SHARED_LOCK);
free(hdr);
}
if (lock) {
if (Examine(lock, fib)) {
r = 0;
while (ExNext(lock, fib)) {
short len;
short prelen = ptr - pat;
if (attr == 0 && fib->fib_DirEntryType > 0)
continue;
if (_CompWild(fib->fib_FileName, wildNode, NULL) < 0)
continue;
if (errno)
break;
len = strlen(fib->fib_FileName) + prelen + 1;
if (len > bufSize) {
r = -1;
break;
}
strncpy(buf, pat, prelen);
strcpy(buf + prelen, fib->fib_FileName);
buf += len;
bufSize -= len;
++r;
}
}
UnLock(lock);
}
free(fib);
}
_FreeWild(wildNode);
if (bufSize > 0)
*buf = 0;
if (errno)
r = -1;
return(r);
}